package com.example.myapplication.util;

import android.content.Context;
import android.graphics.ImageDecoder;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;

import com.example.myapplication.R;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

public class Ad extends PagerAdapter {
    private Context mcontext;
    public int [] guiList = {R.drawable.guide1,R.drawable.guide2,R.drawable.guide3};
    public static List<View> list = new ArrayList<>();
    public Ad(Context mcontext){
        this.mcontext = mcontext;
        for (int i = 0; i < guiList.length; i++) {
            View inflate = LinearLayout.inflate(mcontext, R.layout.viewpager, null);
            Button button = inflate.findViewById(R.id.main_button);
            ImageView imageView = inflate.findViewById(R.id.main_imageview);
            RadioGroup radioGroup = inflate.findViewById(R.id.main_radio);

            imageView.setImageResource(guiList[i]);
            if(i == 2 ){
                button.setVisibility(View.VISIBLE);
            }
            ((RadioButton)radioGroup.getChildAt(i)).setChecked(true);
            list.add(inflate);
        }

    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public boolean isViewFromObject(@NonNull @NotNull View view, @NonNull @NotNull Object object) {
        return view == object;
    }

    @NonNull
    @NotNull
    @Override
    public Object instantiateItem(@NonNull @NotNull ViewGroup container, int position) {
        container.addView(list.get(position));
        return list.get(position);
    }

    @Override
    public void destroyItem(@NonNull @NotNull ViewGroup container, int position, @NonNull @NotNull Object object) {
        container.removeView(list.get(position));

    }
}
